package cn.com.bluemoon.daps.model.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
public class TableListDto {

    @ApiModelProperty(value = "表id")
    private String tableId;

    @ApiModelProperty(value = "关联模型id")
    private String  dataModelId;

    @ApiModelProperty(value = "数据源id")
    private String  dataSourceId;

    @ApiModelProperty(value = "表英文名")
    private String  engName;

    @ApiModelProperty(value = "表中文名")
    private String name;

    @ApiModelProperty(value = "修改状态")
    private Integer tableCategory;

    @ApiModelProperty(value = "表更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "是否为该分组的表")
    private Boolean isGroup = true;

    @ApiModelProperty(value = "字段列表")
    private List<TableFieldListDto> fieldList;

    public SimpleTableDto bean(TableListDto dto){
        SimpleTableDto simpleDto = new SimpleTableDto();
        simpleDto.setId(dto.getTableId());
        simpleDto.setEngName(dto.getEngName());
        return simpleDto;
    }

    public List<SimpleFieldDto> getList(List<TableFieldListDto> fieldList){
        List<SimpleFieldDto> objects = new ArrayList<>();
        for ( TableFieldListDto dto:fieldList) {
            SimpleFieldDto simpleDto = new SimpleFieldDto();
            simpleDto.setId(dto.getId());
            simpleDto.setFieldName(dto.getFieldName());
            objects.add(simpleDto);
        }
        return objects;
    }
}
